home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / OpenDoc 1.2b2c1 / Implementation / Core / NmSpcMg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-13  |  14.4 KB  |  488 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        NmSpcMg.cpp
  3.  
  4.     Contains:    Implementation of ODNameSpaceManager class
  5.  
  6.     Owned by:    Ed Lai
  7.  
  8.     Copyright:    © 1993 - 1995 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <4>     9/23/96    EL        1364617: Fixes leak in DeleteNameSpace
  13.          <3>     6/22/96    EL        1355350: DeleteNameSpace does not remove
  14.                                     namespace as parent
  15.         <21>     8/29/95    DM        1279569: check nil for new SOM instances
  16.         <20>     8/26/95    TÇ        1274606 FB2: Patching Remarks
  17.         <19>     8/25/95    JP        1272288: Added GetAETEs
  18.         <18>      8/3/95    RR        #1257260: Collapse B classes. Remove
  19.                                     somInit methods. Don't call IsInitialized
  20.                                     or SubclassResponsibility
  21.         <17>     7/27/95    DM        #1270320: Mem leaks: temp name in
  22.                                     DeleteNameSpace
  23.         <16>     7/24/95    CG        #1270320: Memory leak fixes.
  24.         <15>     5/25/95    jpa        Return of <12>: HasNameSpace will call
  25.                                     SynchNSTable if the namespace is synched to
  26.                                     the Editors folders. SynchNSTable now
  27.                                     returns a Boolean.  [1240150]
  28.         <14>     5/18/95    CG        #1241621    BB: Need to implement Purge for
  29.                                     Binding subsystem objects.
  30.         <13>     5/17/95    TJ        Backed out changes from previous checkin.
  31.         <11>     5/11/95    DM        #1181622: Updated file ownership.
  32.         <10>     4/26/95    CG        1211082 BB: 5$ Bugs need to be evaluated
  33.                                     and removed from Core
  34.          <9>     4/25/95    DM        1172791: Replace AEHashTable with
  35.                                     OpenHashTable
  36.          <8>      4/6/95    TJ        Fixed Compile Errors.
  37.          <7>      4/5/95    CG        #1216169 BB, #1221135: When Editors folder
  38.                                     or OpenDoc Libraries folder is missing,
  39.                                     OpenDoc quits and displays error.
  40.          <6>     2/14/95    TJ        Fixed copyright date.
  41.          <5>     2/14/95    jpa        Preferences::LoadAnyNewEditors -->
  42.                                     ScanLibsAndEditors [1205141]
  43.          <4>     1/23/95    CG        #1195019: Added field for tracking maximum
  44.                                     length of strings in value name spaces.
  45.          <3>     8/24/94    CG        #1181622: Updated file ownership.
  46.          <2>     8/17/94    CG        #1178378: Destructor now deletes all name
  47.                                     spaces.
  48.          <1>     7/29/94    CG        first checked in
  49.          <3>     6/28/94    VL        Used Translt.xh.
  50.          <2>     6/24/94    CG        SOMized.
  51.          <1>     6/14/94    CG        first checked in
  52.         --------------------------------------------------------------
  53.          <8>      6/1/94    CG        Added fPreferences and associated getters.
  54.          <7>     5/27/94    jpa        New exception support [1165267]
  55.          <6>     5/27/94    CG        #1165186: Abstracted prefs out of binding.
  56.          <5>      5/9/94    MB        #1162181: Changes necessary to install MMM.
  57.          <4>     3/26/94    NP        1152831. Add private stuff.
  58.          <3>     3/15/94    MB        Changes to support SCpp/ASLM builds,
  59.                                     #1150864.
  60.          <2>     2/15/94    CG        #1143680 - NameSpaceManager now being
  61.                                     allocated on specified heap.
  62.          <7>      2/8/94    TÇ        Throw -> THROW & some code clean up
  63.          <6>      2/3/94    CG        System Session break out.
  64.          <5>     1/29/94    NP        Init changes and changed parameters of
  65.                                     CreateNameSpace.
  66.          <4>     1/21/94    CG        More NMAP changes.
  67.          <3>     1/18/94    CG        Changes for new NMAP and for new
  68.                                     XMPNameSpace::GetValue().
  69.          <2>     1/18/94    TÇ        use kOpenDocShellSignature
  70.          <1>     1/14/94    CG        first checked in
  71.     To Do:
  72.     In Progress:
  73. */
  74.  
  75.  
  76. #ifndef _PLFMDEF_
  77. #include "PlfmDef.h"
  78. #endif
  79.  
  80. #define ODNameSpaceManager_Class_Source
  81. #define VARIABLE_MACROS
  82. #include <NmSpcMg.xih>
  83.  
  84. #ifndef SOM_ODNameSpace_xh
  85. #include <NamSpac.xh>
  86. #endif
  87.  
  88. #ifndef SOM_ODObjectNameSpace_xh
  89. #include <ObjectNS.xh>
  90. #endif
  91.  
  92. #ifndef SOM_ODValueNameSpace_xh
  93. #include <ValueNS.xh>
  94. #endif
  95.  
  96. #ifndef SOM_ODObjectIterator_xh
  97. #include <ObjctItr.xh>
  98. #endif
  99.  
  100. #ifndef _STRHSHTB_
  101. #include "StrHshTb.h"
  102. #endif
  103.  
  104. #ifndef _ODTYPES_
  105. #include <ODTypes.h>
  106. #endif
  107.  
  108. #ifndef SOM_Module_OpenDoc_StdDefs_defined
  109. #include <StdDefs.xh>
  110. #endif
  111.  
  112. #ifndef SOM_ODTranslation_xh
  113. #include <Translt.xh>
  114. #endif
  115.  
  116. #ifndef _ODMEMORY_
  117. #include "ODMemory.h"
  118. #endif
  119.  
  120. #ifndef _ISOSTR_
  121. #include "ISOStr.h"
  122. #endif
  123.  
  124. #ifndef _EXCEPT_
  125. #include "Except.h"
  126. #endif
  127.  
  128. #ifndef SOM_ODSession_xh
  129. #include "ODSessn.xh"
  130. #endif
  131.  
  132. #ifndef _PREFS_
  133. #include "Prefs.h"
  134. #endif
  135.  
  136. #ifndef __STRING__
  137. #include <String.h>
  138. #endif
  139.  
  140. #ifndef _ODUTILS_
  141. #include <ODUtils.h>
  142. #endif
  143.  
  144. #ifndef _TEMPOBJ_
  145. #include <TempObj.h>
  146. #endif
  147.  
  148. #pragma segment ODNameSpaceManager
  149.  
  150. #include "NmSpcMgB.cpp"    // Platform-independent methods, if any
  151.  
  152. #define RegisterNameSpaceTable 0
  153.  
  154. //==============================================================================
  155. // Constants
  156. //==============================================================================
  157.  
  158. const ODULong kNumExpectedNameSpaces = 10;
  159.  
  160. //==============================================================================
  161. // ODNameSpaceManager
  162. //==============================================================================
  163.  
  164. //------------------------------------------------------------------------------
  165. // ODNameSpaceManager: InitNameSpaceManager
  166. //------------------------------------------------------------------------------
  167.  
  168. SOM_Scope void  SOMLINK ODNameSpaceManagerInitNameSpaceManager(ODNameSpaceManager *somSelf, Environment *ev,
  169.         ODSession* session)
  170. {
  171.     ODNameSpaceManagerData *somThis = ODNameSpaceManagerGetData(somSelf);
  172.     ODNameSpaceManagerMethodDebug("ODNameSpaceManager","InitNameSpaceManager");
  173.  
  174.     SOM_TRY
  175.  
  176.     /* Moved from somInit. SOM itself sets fields to zero
  177.     _fNameSpaceTable = kODNULL;
  178.     _fPreferences = kODNULL;
  179.     _fMaxISOStrLength = 0;
  180.     */
  181.     somSelf->InitObject(ev);
  182.         
  183.     _fSession = session;
  184.  
  185.     _fNameSpaceTable = new ODObjectNameSpace;
  186.     THROW_IF_NULL(_fNameSpaceTable); // check all SOM new's for nil
  187.  
  188.     { TempODISOStr    objName = ODISOStrFromCStr("NameSpaceTable");
  189.       _fNameSpaceTable->InitObjectNameSpace(ev, somSelf, kODNULL, 
  190.                                 kNumExpectedNameSpaces, objName);
  191. #if RegisterNameSpaceTable
  192.       _fNameSpaceTable->Register(ev, objName, (ODObject*)_fNameSpaceTable);
  193. #endif
  194.     }
  195.     
  196.     _fPreferences = new Preferences();
  197.     _fPreferences->InitPreferences(session);
  198.  
  199.     SOM_CATCH_ALL
  200.     SOM_ENDTRY
  201. }
  202.  
  203. //------------------------------------------------------------------------------
  204. // ODNameSpaceManager: HasNameSpace
  205. //------------------------------------------------------------------------------
  206.  
  207. SOM_Scope ODNameSpace*  SOMLINK ODNameSpaceManagerHasNameSpace(ODNameSpaceManager *somSelf, Environment *ev,
  208.         ODISOStr spaceName)
  209. {
  210.     ODNameSpaceManagerData *somThis = ODNameSpaceManagerGetData(somSelf);
  211.     ODNameSpaceManagerMethodDebug("ODNameSpaceManager","HasNameSpace");
  212.  
  213.     ODNameSpace*     theNameSpace = kODNULL;
  214.  
  215.     SOM_TRY
  216.         // Look in namespace table for spacename
  217.     _fNameSpaceTable->GetEntry (ev, spaceName, (ODObject**)&theNameSpace);
  218.             
  219.     // If this namespace is read from the Editors folder(s), make sure the namespaces
  220.     // are synched to the current Editors folder(s):
  221.     if( theNameSpace && theNameSpace->IsSynchedToEditors(ev) )
  222.         if( somSelf->SynchNSTable(ev) ) {
  223.             // Synching causes the namespaces to be recreated, so the pointer is
  224.             // no longer valid. Get a new pointer:
  225.             _fNameSpaceTable->GetEntry (ev, spaceName, (ODObject**)&theNameSpace);
  226.         }
  227.             
  228.     SOM_CATCH_ALL
  229.     SOM_ENDTRY
  230.  
  231.     return theNameSpace;
  232. }
  233.  
  234.  
  235.  
  236. //------------------------------------------------------------------------------
  237. // ODNameSpaceManager: ~ODNameSpaceManager
  238. //------------------------------------------------------------------------------
  239.  
  240. SOM_Scope void  SOMLINK ODNameSpaceManagersomUninit(ODNameSpaceManager *somSelf)
  241. {
  242.     ODNameSpaceManagerData *somThis = ODNameSpaceManagerGetData(somSelf);
  243.     ODNameSpaceManagerMethodDebug("ODNameSpaceManager","somUninit");
  244.  
  245.     Environment* ev = somGetGlobalEnvironment();
  246.     
  247.     // $opt: SOM_TRY should not be necessary around deletions and another somUninit.
  248.     SOM_TRY
  249.     
  250. #if RegisterNameSpaceTable
  251.         { TempODISOStr name = _fNameSpaceTable->GetName(ev);
  252.           _fNameSpaceTable->Unregister(ev, name);
  253.         }
  254. #endif
  255.     
  256.         ODDeleteObject( _fNameSpaceTable );
  257.     
  258.         ODDeleteObject( _fPreferences );
  259.  
  260.     ODNameSpaceManager_parent_ODObject_somUninit(somSelf);
  261.  
  262.     SOM_CATCH_ALL
  263.     SOM_ENDTRY
  264. }
  265.  
  266. //------------------------------------------------------------------------------
  267. // ODNameSpaceManager: Purge
  268. //------------------------------------------------------------------------------
  269.  
  270. SOM_Scope ODSize  SOMLINK ODNameSpaceManagerPurge(ODNameSpaceManager *somSelf, Environment *ev,
  271.         ODSize size)
  272. {
  273.     ODNameSpaceManagerData *somThis = ODNameSpaceManagerGetData(somSelf);
  274.     ODNameSpaceManagerMethodDebug("ODNameSpaceManager","Purge");
  275.  
  276.     ODSize    purgeSize = 0; ODVolatile( purgeSize );
  277.     
  278.     SOM_TRY
  279.  
  280.         purgeSize = _fPreferences->Purge(size);
  281.         purgeSize += parent_Purge( somSelf, ev, size );
  282.     SOM_CATCH_ALL
  283.         WARN("Error %ld trying to purge in ODNameSpaceManagerPurge",ErrorCode());
  284.         SetErrorCode(kODNoError);        // dh - Eat the exception; Purge should not 
  285.                                         // propagate it because clients function
  286.                                         // fine whether memory was purged or not.
  287.     SOM_ENDTRY
  288.  
  289.     return purgeSize;
  290. }
  291.  
  292. //------------------------------------------------------------------------------
  293. // ODNameSpaceManager: CreateNameSpace
  294. //------------------------------------------------------------------------------
  295.  
  296. SOM_Scope ODNameSpace*  SOMLINK ODNameSpaceManagerCreateNameSpace(ODNameSpaceManager *somSelf, Environment *ev,
  297.         
  298.                                             ODISOStr        spaceName,
  299.                                             ODNameSpace*    inheritsFrom,
  300.                                             ODULong            numExpectedEntries,
  301.                                             ODNSTypeSpec    type)
  302. {
  303.     ODNameSpaceManagerData *somThis = ODNameSpaceManagerGetData(somSelf);
  304.     ODNameSpaceManagerMethodDebug("ODNameSpaceManager","CreateNameSpace");
  305.  
  306.     ODNameSpace* nameSpace = kODNULL;
  307.  
  308.     SOM_TRY
  309.  
  310.     nameSpace = somSelf->HasNameSpace(ev,spaceName);
  311.     if ( nameSpace )
  312.         //THROW(kODErrKeyAlreadyExists);
  313.         nameSpace = (ODNameSpace*)kODNULL;
  314.     else
  315.     {
  316.         switch (type)
  317.         {
  318.             case kODNSDataTypeODObject:
  319.             {
  320.                 ODObjectNameSpace* objNameSpace = new ODObjectNameSpace;
  321.                 THROW_IF_NULL(objNameSpace); // check all SOM new's for nil
  322.                 objNameSpace->InitObjectNameSpace(ev,somSelf, inheritsFrom,
  323.                                             numExpectedEntries, spaceName);
  324.                 _fNameSpaceTable->Register(ev, spaceName, (ODObject*)objNameSpace);
  325.                 nameSpace = (ODNameSpace*) objNameSpace;
  326.                 break;
  327.             }
  328.  
  329.             case kODNSDataTypeODValue:
  330.             {
  331.                 ODValueNameSpace* valNameSpace = new ODValueNameSpace;
  332.                 THROW_IF_NULL(valNameSpace); // check all SOM new's for nil
  333.                 valNameSpace->InitValueNameSpace(ev,somSelf, inheritsFrom,
  334.                                             numExpectedEntries, spaceName);
  335.                 _fNameSpaceTable->Register(ev, spaceName, (ODObject*)valNameSpace);
  336.                 nameSpace =  (ODNameSpace*) valNameSpace;
  337.                 break;
  338.             }
  339.                 
  340.             default:
  341.             {
  342.                 nameSpace = (ODNameSpace*)kODNULL;
  343.                 break;
  344.             }
  345.         }
  346.     }
  347.  
  348.     SOM_CATCH_ALL
  349.     SOM_ENDTRY
  350.     return nameSpace;
  351. }
  352.  
  353.  
  354. //------------------------------------------------------------------------------
  355. // ODNameSpaceManager: DeleteNameSpace
  356. //------------------------------------------------------------------------------
  357.  
  358. SOM_Scope void  SOMLINK ODNameSpaceManagerDeleteNameSpace(ODNameSpaceManager *somSelf, Environment *ev,
  359.         ODNameSpace* nameSpace)
  360. {
  361.     ODNameSpaceManagerData *somThis = ODNameSpaceManagerGetData(somSelf);
  362.     ODNameSpaceManagerMethodDebug("ODNameSpaceManager","DeleteNameSpace");
  363.  
  364.     ODISOStr                nsName;
  365.     ODObject*                nsObject;
  366.     ODULong                    length;
  367.  
  368.     
  369.     SOM_TRY
  370.  
  371.     { TempODISOStr name = nameSpace->GetName(ev);
  372.       _fNameSpaceTable->Unregister(ev, name);
  373.     }
  374.  
  375.     ODObjectIterator*    iter = _fNameSpaceTable->CreateIterator(ev);
  376.     for (iter->First(ev, &nsName, &nsObject, &length);
  377.             iter->IsNotComplete(ev);
  378.             iter->Next(ev, &nsName, &nsObject, &length))
  379.     {
  380.         if (ODObjectsAreEqual(ev, ((ODNameSpace*)nsObject)->GetParent(ev), nameSpace))
  381.             ((ODObjectNameSpace*)nsObject)->NotifyDying(ev, nameSpace);
  382.         ODDisposePtr(nsName);
  383.     }
  384.     
  385.     ODDeleteObject( iter );
  386.  
  387.     ODDeleteObject( nameSpace );
  388.  
  389.     SOM_CATCH_ALL
  390.     SOM_ENDTRY
  391. }
  392.  
  393.  
  394. //------------------------------------------------------------------------------
  395. // ODNameSpaceManager: GetPreferences
  396. //------------------------------------------------------------------------------
  397.  
  398. SOM_Scope Preferences*  SOMLINK ODNameSpaceManagerGetPreferences(ODNameSpaceManager *somSelf, Environment *ev)
  399. {
  400.     ODNameSpaceManagerData *somThis = ODNameSpaceManagerGetData(somSelf);
  401.     ODNameSpaceManagerMethodDebug("ODNameSpaceManager","GetPreferences");
  402.  
  403.     return _fPreferences;
  404. }
  405.  
  406. //------------------------------------------------------------------------------
  407. // ODNameSpaceManager: SynchNSTable
  408. //------------------------------------------------------------------------------
  409.  
  410. SOM_Scope ODBoolean  SOMLINK ODNameSpaceManagerSynchNSTable(ODNameSpaceManager *somSelf, Environment *ev)
  411. {
  412.     ODNameSpaceManagerData *somThis = ODNameSpaceManagerGetData(somSelf);
  413.     ODNameSpaceManagerMethodDebug("ODNameSpaceManager","SynchNSTable");
  414.  
  415.     ODBoolean result = kODFalse;
  416.     
  417.     SOM_TRY
  418.  
  419.     result = _fPreferences->ScanLibsAndEditors();
  420.  
  421.     SOM_CATCH_ALL
  422.     SOM_ENDTRY
  423.     
  424.     return result;
  425. }
  426.  
  427. //------------------------------------------------------------------------------
  428. // ODNameSpaceManager: UpdatePreferences
  429. //------------------------------------------------------------------------------
  430.  
  431. SOM_Scope void  SOMLINK ODNameSpaceManagerUpdatePreferences(ODNameSpaceManager *somSelf, Environment *ev)
  432. {
  433.     ODNameSpaceManagerData *somThis = ODNameSpaceManagerGetData(somSelf);
  434.     ODNameSpaceManagerMethodDebug("ODNameSpaceManager","UpdatePreferences");
  435.  
  436.     SOM_TRY
  437.  
  438.     _fPreferences->UpdatePreferences();
  439.  
  440.     SOM_CATCH_ALL
  441.     SOM_ENDTRY
  442. }
  443.  
  444. //------------------------------------------------------------------------------
  445. // ODNameSpaceManager: GetMaxISOStrLength
  446. //------------------------------------------------------------------------------
  447.  
  448. SOM_Scope ODULong  SOMLINK ODNameSpaceManagerGetMaxISOStrLength(ODNameSpaceManager *somSelf, Environment *ev)
  449. {
  450.     ODNameSpaceManagerData *somThis = ODNameSpaceManagerGetData(somSelf);
  451.     ODNameSpaceManagerMethodDebug("ODNameSpaceManager","GetMaxISOStrLength");
  452.  
  453.     return _fMaxISOStrLength;
  454. }
  455.  
  456. //------------------------------------------------------------------------------
  457. // ODNameSpaceManager: SetMaxISOStrLength
  458. //------------------------------------------------------------------------------
  459.  
  460. SOM_Scope void  SOMLINK ODNameSpaceManagerSetMaxISOStrLength(ODNameSpaceManager *somSelf, Environment *ev,
  461.     ODULong newLength)
  462. {
  463.     ODNameSpaceManagerData *somThis = ODNameSpaceManagerGetData(somSelf);
  464.     ODNameSpaceManagerMethodDebug("ODNameSpaceManager","SetMaxISOStrLength");
  465.  
  466.     _fMaxISOStrLength = newLength;
  467. }
  468.  
  469. //------------------------------------------------------------------------------
  470. // ODNameSpaceManager: GetAETEs
  471. //------------------------------------------------------------------------------
  472.  
  473. SOM_Scope void  SOMLINK ODNameSpaceManagerGetAETEs(ODNameSpaceManager *somSelf, Environment *ev, 
  474.         ODSLong languageCode, AEDescList* aeteList)
  475. {
  476.     ODNameSpaceManagerData *somThis = ODNameSpaceManagerGetData(somSelf);
  477.     ODNameSpaceManagerMethodDebug("ODNameSpaceManager","GetAETEs");
  478.  
  479.     SOM_TRY
  480.  
  481.     _fPreferences->GetAETEs(languageCode, aeteList);
  482.  
  483.     SOM_CATCH_ALL
  484.     SOM_ENDTRY
  485. }
  486.  
  487.  
  488.